package com.example.reactor.reactor;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Schedulers {
    private static final ExecutorService defaultExecutor = Executors.newCachedThreadPool();

    // 使用默认线程池执行任务
    public static void executeAsync(Runnable task) {
        defaultExecutor.submit(task);
    }

    // 支持用户自定义线程池
    public static void executeWithExecutor(Executor executor, Runnable task) {
        executor.execute(task);
    }

    // 并行执行多个任务
    public static void executeParallel(List<Runnable> tasks) {
        for (Runnable task : tasks) {
            defaultExecutor.submit(task);
        }
    }

    // 关闭调度器
    public static void shutdown() {
        defaultExecutor.shutdown();
    }
}